package thread;

/**
 * @author 老安
 * @data 2022/6/23 19:37
 * 获取线程相关的一组方法
 */
public class ThreadInfoDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();//获取到主线程
        String name = main.getName();//获取线程名
        System.out.println("名字:"+name);
        long id = main.getId();//获取线程的唯一标识(类似于人的身份证号)
        System.out.println("id:"+id);
        int priority = main.getPriority();//获取线程的优先级
        System.out.println("优先级:"+priority);

        boolean alive = main.isAlive();//线程是否还活着
        boolean daemon = main.isDaemon();//线程是否为守护线程
        boolean interrupted = main.isInterrupted();//线程是否被中断了
        System.out.println("是否活着:"+alive);
        System.out.println("是否为守护线程:"+daemon);
        System.out.println("是否被中断:"+interrupted);
    }
}
